<template>
  <div class="login">
      <div class="logo">
          <img :src="`https://hekas.oss-cn-hangzhou.aliyuncs.com/images/global/app-c-avatar.jpeg?t=${new Date().getTime()}`" alt="">
      </div>
      <div class="title">让你的礼物更有心意</div>
    <!-- 获取手机号使用手机号登录 -->
    <button  type="primary" class='btn' open-type="getPhoneNumber"
             @getphonenumber="handleLogin">微信手机号登录</button>
  </div>
</template>

<script>
import {getSystemAgreement, getUserInfo, setPhone} from "../../api";

export default {
  name: "index",
    onShow() {
        wx.setStorageSync('token', '')
    },
    onLoad() {
        wx.setStorageSync('token', '')
    },
  methods: {
    async handleLogin(e) {
          if (e.detail.errMsg !== 'getPhoneNumber:ok'){
            uni.showToast({
              title: '拒绝手机号登录',
              icon: "none",
              duration: 3000
            });
            return;
          }
          setPhone(e.detail.code).then(res => {
              wx.setStorageSync('userInfo', {
                  ...(wx.getStorageSync('userInfo') || {}),
                  phone: res.data
              })
              wx.navigateBack()
          })
    }
  }
}
</script>

<style lang="less">
.login {
    width: 100%;
    height: 100vh;
    background: #eeeeee;
    .logo {
        display: flex;
        justify-content: center;
        align-items: center;
        padding-top: 80px;
        margin-bottom: 20px;
        img {
            margin: 0 auto;
            width: 100px;
            height: 100px;
            border-radius: 12px;
            overflow: hidden;
        }
    }
    .title {
        margin-bottom: 100px;
        text-align: center;
        font-size: 12px;
        color: #999999;
    }
    .btn {
        margin: 0 auto;
        width: 200px;
        height: 42px;
        line-height: 42px;
        font-size: 14px;
        color: #000000;
        background-color: #00C65A;
    }
}
</style>
